<?php
date_default_timezone_set('Asia/Shanghai');
$conn=mysql_connect("localhost","root","gsda1.mysql1");
mysql_select_db("new_gsdai", $conn);
mysql_query("SET character_set_results = 'utf8', character_set_client = 'utf8', character_set_connection = 'utf8', character_set_database = 'utf8', character_set_server = 'utf8'", $conn);
$ctime = time();
$sql = "select id,lz_endtime from ych_borrow where ftype=4 and lz_endtime>$ctime";

$result = db_fetch_arrays($sql, $conn);
foreach ($result as $key => $value){
	$borrow_id = $value['id'];
	$lztime = $value['lz_endtime'];
	$lz_house = date('H' ,$lztime);
	$lz_year = date('Y' ,$lztime);
	$lz_month = date('m' ,$lztime);
	$lz_day = date('d' ,$lztime);
	/*if($lz_house > 10){
		echo $value['id'].' = '.date('Y-m-d H:i:s' ,$lztime);
		echo "，";
		$a = $lz_house-9;
		$end_lz = strtotime($lz_year.'-'.$lz_month.'-'.$lz_day.' 09:00:00');
		echo date('Y-m-d H:i:s',$end_lz);
		echo "\n";
	}*/
	if($lz_house > 9){
		$end_lz = strtotime($lz_year.'-'.$lz_month.'-'.$lz_day.' 09:00:00');
		$sql = "update ych_borrow set lz_endtime={$end_lz} where id={$borrow_id}";
		$query = mysql_query($sql, $conn);
		if(!$query){
			echo $sql;
			exit;
		}
	}
}
echo "over";


function db_fetch_arrays($sql, $conn) 	{
	$result = mysql_query($sql, $conn);
	$i = 0;
	$_res = array();
	while($res = mysql_fetch_array($result,MYSQL_ASSOC)) {
		foreach ($res as $key => $value){
			$_res[$i][$key] = $value;//直接转义
		}
		$i++;
	}
	return $_res;
}

function db_fetch_array($sql,$conn) {
		$result = mysql_query($sql, $conn);
		$res = mysql_fetch_array($result,MYSQL_ASSOC);
		$_res = "";
		if (is_array($res)){
			foreach ($res as $key => $value){
				$_res[$key] =$value;
			}
		}
		$query = $_res;
		return $query;
}